This is, in effect, "hello, world" in the realm of coroutines. If you run this, you will see one message printed immediately and the other after a short delay.
There are five main elements when working with coroutines:
A
CoroutineScope, such as theGlobalScopethat is used hereA coroutine builder, such as the
launch()function onGlobalScopeDispatchers, such as
Dispatchers.DefaultandDispatchers.Mainsuspendfunctions, for marking code that can be suspended safely so other code can runA
CoroutineContext, such as the one created viawithContext(), to change which dispatcher should be used for some code
All of these will be explored in upcoming lessons.
You can learn more about this in:
Tags: